package com.social.util;

import com.social.pojo.RegistrationOfCases;
import com.social.pojo.SpecialAuditMaterials;
import com.social.pojo.Ultimate;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 对象封装工具类
 */
public class ObjectUtil {
    /**
     * 科长实体类
     *
     * @param registrationOfCases 实体类
     * @return 实体类数据
     */
    public static Ultimate getUltimate(RegistrationOfCases registrationOfCases) {
        //当立案审核通过 转至科长审核
        Ultimate ultimate = new Ultimate();
        ultimate.setId(registrationOfCases.getId());
        ultimate.setUnitName(registrationOfCases.getUnitName());
        ultimate.setOrganizationalCode(registrationOfCases.getOrganizationalCode());
        ultimate.setNameOfTheComplainant(registrationOfCases.getNameOfTheComplainant());
        ultimate.setIdCard(registrationOfCases.getIdCard());
        ultimate.setPhone(registrationOfCases.getPhone());
        ultimate.setAccountCharacter(registrationOfCases.getAccountCharacter());
        ultimate.setAge(registrationOfCases.getAge());
        ultimate.setSex(registrationOfCases.getSex());
        ultimate.setComplaintContents(registrationOfCases.getComplaintContents());
        ultimate.setNameOfRegistrant(registrationOfCases.getNameOfRegistrant());
        ultimate.setRegistrationTime(registrationOfCases.getRegistrationTime());
        ultimate.setNameOfTheFiler(registrationOfCases.getNameOfTheFiler());
        ultimate.setFilingMonth(registrationOfCases.getFilingMonth());
        ultimate.setFilingTime(registrationOfCases.getFilingTime());
        ultimate.setApprovalStatus(0);
        ultimate.setWarningTime(0);
        ultimate.setNumberOfAuditors(registrationOfCases.getNumberOfAuditors());
        ultimate.setAuditHouseholds(registrationOfCases.getAuditHouseholds());
        ultimate.setAmountPaid(registrationOfCases.getAmountPaid());
        ultimate.setTypeStatus(registrationOfCases.getTypeStatus());
        return ultimate;
    }

    /**
     * @param id         RegistrationOfCases primary key
     * @param v          随机号
     * @param yyyyMMddHH 年月日
     * @param fileName   文件名
     * @return SpecialAuditMaterials 对象
     */
    public static SpecialAuditMaterials getSpecialAuditMaterials(Integer id, double v, String yyyyMMddHH, String fileName) {
        //实体类对象
        SpecialAuditMaterials specialAuditMaterials = new SpecialAuditMaterials();
        //设置文件id
        specialAuditMaterials.setRegistrationOfCasesId(id);
        //设置文件路径
        specialAuditMaterials.setAuditReportUrl("/files/" + (int) v + yyyyMMddHH + fileName);
        //上传时间
        specialAuditMaterials.setTime(yyyyMMddHH);
        //已上传状态
        specialAuditMaterials.setState(1);
        return specialAuditMaterials;
    }

    public static String getAge(String pensonnelIdCard) {
        //截取出生年月日
        String birthday = pensonnelIdCard.substring(6, 14);
        //当前日期
        String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
        //计算年龄差
        Integer ageBit = Integer.parseInt(date) - Integer.parseInt(birthday);
        //计算后的年龄
        Integer personAge;
        //当年龄差的长度大于4位时，即出生年份小于当前年份
        if (ageBit.toString().length() > 4) {
            //截取掉后四位即为年龄
            personAge = Integer.parseInt(ageBit.toString().substring(0, ageBit.toString().length() - 4));
            System.out.println("计算年龄:" + personAge);
        } else {
            //当前年份出生，直接赋值为0岁
            personAge = 0;
            System.out.println("计算年龄:" + personAge);
        }
        return String.valueOf(personAge);
    }
}
